package cn.tedu.lbs.article.web.service;

import cn.tedu.lbs.article.web.repository.CategoryRepository;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.basic.po.ArticleCategoryPO;
import com.tarena.lbs.pojo.content.vo.ArticleCategoryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class CategoryService {
    @Autowired
    private CategoryRepository categoryRepository;

    public PageResult<ArticleCategoryVO> list() {
        PageResult<ArticleCategoryVO> pageResult
                = new PageResult<>(10,1);
        pageResult.setTotal(100l);
        List<ArticleCategoryPO> pos = categoryRepository.list();
        pageResult.setObjects(pos.stream().map(po->{
            ArticleCategoryVO vo=new ArticleCategoryVO();
            BeanUtils.copyProperties(po,vo);
            return vo;
        }).collect(Collectors.toList()));
        return pageResult;
    }
}
